public class Solution_7 {
    public int reverse(int x) {
        if (-10 < x && x < 10) {
            return x;
        }
        int res = 0;
        while(x != 0) {
            int t = x % 10;
            int newRes = res * 10 + t;
            if ((newRes - t) / 10 != res) {
                return 0;
            }
            res = newRes;
            x = x / 10;
        }
        return res;
    }

    public static void main(String[] args) {
        int x = -120;
        int ans = new Solution_7().reverse(x);
        System.out.println(ans);
    }
}
